home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / stereo / GL_5.2 / stereowin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.5 KB  |  166 lines

  1. /*
  2.  * Copyright (C) 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * Simple code to support stereo windows
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <malloc.h>
  23.  
  24. #define USE_X
  25.  
  26. #include "stereo.h"
  27. #include "glxhelper.h"
  28.  
  29. #include "SGIStereo.h"
  30.  
  31. typedef struct StereoWindow
  32. {
  33.     long st_id;
  34.  
  35.     Window win;
  36.  
  37.     struct StereoWindow *next, *prev;
  38. } StereoWindow;
  39.  
  40. static StereoWindow *head = NULL;
  41. static int numwindows = 0;
  42.  
  43. Display  * dpy;
  44.  
  45. long
  46. st_winopen(char *title, int primary, int *softStereo)
  47. {
  48.     Window     root,glW;
  49.     int        screen_num;
  50.     XEvent     event;
  51.     XSizeHints hints;
  52.     int        ival, status;
  53.  
  54.     Window retroot, tmpWin;
  55.     int ox, oy;
  56.     unsigned int sx, sy, bw, depth;
  57.  
  58.     StereoWindow *new_window;
  59.  
  60.     if((dpy=XOpenDisplay(0)) == NULL) {
  61.     fprintf(stderr,"\ncannot connect to X server\n");
  62.         exit(-1);
  63.     }
  64.  
  65.     screen_num = DefaultScreen(dpy);
  66.     root = RootWindow(dpy,screen_num);
  67.  
  68.     if(XSGIStereoQueryExtension(dpy, &ival, &status))
  69.     {
  70.         printf("SoftStereo supported\n");
  71.         *softStereo = TRUE;
  72.     }else{
  73.         printf("SoftStereo NOT supported\n");
  74.         *softStereo = FALSE;
  75.         exit(1);
  76.     }
  77.  
  78.     if (numwindows == 0)
  79.     {
  80.     foreground();
  81.     noport();
  82.     winopen(title);    /* Initialize graphics, then... */
  83.         if(!softStereo)
  84.             stereo_on(STR_RECT);
  85.         else
  86.         stereo_on(primary);    /* Turn on stereo mode */
  87.     }
  88.     ++numwindows;
  89.  
  90.     new_window = (StereoWindow *)malloc(sizeof(StereoWindow));
  91.  
  92.     new_window->st_id = numwindows;
  93.  
  94.     new_window->next = head;
  95.     new_window->prev = NULL;
  96.  
  97.     head = new_window;
  98.  
  99.     new_window->win = GLXCreateWindow(dpy, root, 0, 0, 700, 400, 0, GLXrgbDoubleBuffer);
  100.  
  101.     XStoreName(dpy, new_window->win, title);
  102.     XSelectInput(dpy,new_window->win,Button2MotionMask|
  103.         PointerMotionHintMask | StructureNotifyMask | 
  104.         ButtonPressMask|ButtonReleaseMask|ExposureMask|KeyPressMask);
  105.     XMapWindow(dpy,new_window->win);
  106.     GLXwinset(dpy, new_window->win);
  107.  
  108.     XNextEvent(dpy, &event);
  109.  
  110.     XSync(dpy,False);
  111.     return new_window->st_id;
  112. }
  113.  
  114. static StereoWindow *
  115. find_window(long id)
  116. {
  117.     StereoWindow *scan;
  118.     for (scan = head; scan != NULL; scan = scan->next)
  119.     {
  120.         if (scan->st_id == id) break;
  121.     }
  122.     return scan;
  123. }
  124.  
  125. void
  126. st_winclose(long id)
  127. {
  128.     StereoWindow *w;
  129.     if ((w = find_window(id)) != NULL)
  130.     {
  131.         /* Unlink from list */
  132.         if (w == head)
  133.             head = w->next;
  134.         if (w->prev != NULL)
  135.             w->prev->next = w->next;
  136.         if (w->next != NULL)
  137.             w->next->prev = w->prev;
  138.  
  139.         /* Free storage */
  140.         free(w);
  141.     }
  142. }
  143.  
  144. void
  145. st_right(long st_id)
  146. {
  147.     StereoWindow *w;
  148.     if ((w = find_window(st_id)) != NULL)
  149.     {
  150.         XSGISetStereoBuffer(dpy, w->win, STEREO_BUFFER_RIGHT);
  151.         XSync(dpy, False);
  152.     }
  153. }
  154.  
  155. void
  156. st_left(long st_id)
  157. {
  158.     StereoWindow *w;
  159.     if ((w = find_window(st_id)) != NULL)
  160.     {
  161.         XSGISetStereoBuffer(dpy, w->win, STEREO_BUFFER_LEFT);
  162.         XSync(dpy, False);
  163.     }
  164. }
  165.  
  166.